home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / streaming / qtspacketizerreassembler / componentvideortp / sources / componentvideopayload.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.8 KB  |  250 lines

  1. /*
  2.     File:        ComponentVideoPayload.c
  3.  
  4.     Contains:    Definition of ComponentVideoPayload operations
  5.  
  6.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  7.     
  8. */
  9.  
  10.  
  11.  
  12. #include "ComponentVideoPayload.h"
  13. #include <Endian.h>
  14. #include <string.h>
  15.  
  16.  
  17.  
  18. enum    /* fixed header fields */
  19. {
  20.     __kDescriptionFlagWord        = 0,
  21.     __kDescriptionFlagPosition    = 31,
  22.     __kDescriptionFlagSize        = 1,
  23.     
  24.     __kDescriptionSeedWord        = 0,
  25.     __kDescriptionSeedPosition    = 0,
  26.     __kDescriptionSeedSize        = 31,
  27.     
  28.     __kOffsetWord                = 1,
  29.     __kOffsetPosition            = 4,
  30.     __kOffsetSize                = 28
  31. };
  32.  
  33. enum    /* payload description fields */
  34. {
  35.     __kWidthWord                = 0,
  36.     __kWidthPosition            = 15,
  37.     __kWidthSize                = 15,
  38.     
  39.     __kHeightWord                = 0,
  40.     __kHeightPosition            = 0,
  41.     __kHeightSize                = 15
  42. };
  43.  
  44.  
  45.  
  46. static
  47. UInt32
  48. __SetBitField(
  49.     UInt32 *    inStorageUnit,
  50.     UInt32        inPosition,
  51.     UInt32        inSize,
  52.     UInt32        inValue )
  53. {
  54.     UInt32    theMask = ( ( 1UL << inSize ) - 1 ) << inPosition;
  55.     
  56.     
  57.     *inStorageUnit =
  58.         EndianU32_NtoB(
  59.             ( EndianU32_BtoN( *inStorageUnit ) & ( ~theMask ) ) |
  60.             ( theMask & ( inValue << inPosition ) ) );
  61.     
  62.     return( inValue & ( theMask >> inPosition ) );
  63. }
  64.  
  65.  
  66.  
  67. static
  68. UInt32
  69. __BitField(
  70.     const UInt32 *    inStorageUnit,
  71.     UInt32            inPosition,
  72.     UInt32            inSize )
  73. {
  74.     return( ( EndianU32_BtoN( *inStorageUnit ) >> inPosition ) & ( ( 1UL << inSize ) - 1 ) );
  75. }
  76.  
  77.  
  78.  
  79. UInt32
  80. ComponentVideoPayloadDescriptionSeedLimit(
  81.     void )
  82. {
  83.     return( ( 1UL << __kDescriptionSeedSize ) - 1 );
  84. }
  85.  
  86.  
  87.  
  88. ComponentVideoPayload *
  89. ComponentVideoPayloadInitialize(
  90.     ComponentVideoPayload *        inPayload,
  91.     UInt16                        inWidth,
  92.     UInt16                        inHeight )
  93. {
  94.     memset( inPayload, 0, sizeof( *inPayload ) );
  95.     
  96.     ComponentVideoPayloadSetDescription( inPayload, inWidth, inHeight );
  97.     
  98.     return( inPayload );
  99. }
  100.  
  101.  
  102.  
  103. UInt32
  104. ComponentVideoPayloadSetOffset(
  105.     ComponentVideoPayload *        inPayload,
  106.     UInt32                        inOffset )
  107. {
  108.     UInt32    theResult;
  109.     
  110.     
  111.     theResult =
  112.         __SetBitField(
  113.             &inPayload->itsFixedHeader[ __kOffsetWord ], __kOffsetPosition, __kOffsetSize,
  114.             inOffset >> 2 ) << 2;
  115.     
  116.     return( theResult );
  117. }
  118.  
  119.  
  120.  
  121. UInt32
  122. ComponentVideoPayloadSetDescription(
  123.     ComponentVideoPayload *        inPayload,
  124.     UInt16                        inWidth,
  125.     UInt16                        inHeight )
  126. {
  127.     UInt32    theResult;
  128.     
  129.     
  130.     theResult = ComponentVideoPayloadDescriptionSeed( inPayload );
  131.     
  132.     if( inWidth  &&  inHeight )
  133.     {
  134.         if(
  135.             inWidth != ComponentVideoPayloadWidth( inPayload )  ||
  136.             inHeight != ComponentVideoPayloadHeight( inPayload ) )
  137.         {
  138.             theResult =
  139.                 __SetBitField(
  140.                     &inPayload->itsFixedHeader[ __kDescriptionSeedWord ],
  141.                     __kDescriptionSeedPosition, __kDescriptionSeedSize, theResult + 1 );
  142.             
  143.             __SetBitField(
  144.                 &inPayload->itsDescription[ __kWidthWord ], __kWidthPosition, __kWidthSize,
  145.                 inWidth );
  146.             
  147.             __SetBitField(
  148.                 &inPayload->itsDescription[ __kHeightWord ], __kHeightPosition,
  149.                 __kHeightSize, inHeight );
  150.         }
  151.     }
  152.     
  153.     __SetBitField(
  154.         &inPayload->itsFixedHeader[ __kDescriptionFlagWord ], __kDescriptionFlagPosition,
  155.         __kDescriptionFlagSize, inWidth  &&  inHeight );
  156.     
  157.     return( theResult );
  158. }
  159.  
  160.  
  161.  
  162. UInt32
  163. ComponentVideoPayloadCopyDescription(
  164.     ComponentVideoPayload *            inTargetPayload,
  165.     const ComponentVideoPayload *    inSourcePayload )
  166. {
  167.     UInt32    theResult;
  168.     
  169.     
  170.     __SetBitField(
  171.         &inTargetPayload->itsFixedHeader[ __kDescriptionFlagWord ],
  172.         __kDescriptionFlagPosition, __kDescriptionFlagSize,
  173.         ComponentVideoPayloadHasDescription( inSourcePayload ) );
  174.     
  175.     theResult =
  176.         __SetBitField(
  177.             &inTargetPayload->itsFixedHeader[ __kDescriptionSeedWord ],
  178.             __kDescriptionSeedPosition, __kDescriptionSeedSize,
  179.             ComponentVideoPayloadDescriptionSeed( inSourcePayload ) );
  180.     
  181.     __SetBitField(
  182.         &inTargetPayload->itsDescription[ __kWidthWord ], __kWidthPosition, __kWidthSize,
  183.         ComponentVideoPayloadWidth( inSourcePayload ) );
  184.     
  185.     __SetBitField(
  186.         &inTargetPayload->itsDescription[ __kHeightWord ], __kHeightPosition, __kHeightSize,
  187.         ComponentVideoPayloadHeight( inSourcePayload ) );
  188.     
  189.     return( theResult );
  190. }
  191.  
  192.  
  193.  
  194. Boolean
  195. ComponentVideoPayloadHasDescription(
  196.     const ComponentVideoPayload *    inPayload )
  197. {
  198.     return(
  199.         __BitField(
  200.             &inPayload->itsFixedHeader[ __kDescriptionFlagWord ],
  201.             __kDescriptionFlagPosition, __kDescriptionFlagSize ) );
  202. }
  203.  
  204.  
  205.  
  206. UInt32
  207. ComponentVideoPayloadDescriptionSeed(
  208.     const ComponentVideoPayload *    inPayload )
  209. {
  210.     return(
  211.         __BitField(
  212.             &inPayload->itsFixedHeader[ __kDescriptionSeedWord ],
  213.             __kDescriptionSeedPosition, __kDescriptionSeedSize ) );
  214. }
  215.  
  216.  
  217.  
  218. UInt32
  219. ComponentVideoPayloadOffset(
  220.     const ComponentVideoPayload *    inPayload )
  221. {
  222.     return(
  223.         __BitField(
  224.             &inPayload->itsFixedHeader[ __kOffsetWord ], __kOffsetPosition,
  225.             __kOffsetSize ) << 2 );
  226. }
  227.  
  228.  
  229.  
  230. UInt16
  231. ComponentVideoPayloadWidth(
  232.     const ComponentVideoPayload *    inPayload )
  233. {
  234.     return(
  235.         __BitField(
  236.             &inPayload->itsDescription[ __kWidthWord ], __kWidthPosition, __kWidthSize ) );
  237. }
  238.  
  239.  
  240.  
  241. UInt16
  242. ComponentVideoPayloadHeight(
  243.     const ComponentVideoPayload *    inPayload )
  244. {
  245.     return(
  246.         __BitField(
  247.             &inPayload->itsDescription[ __kHeightWord ], __kHeightPosition,
  248.             __kHeightSize ) );
  249. }
  250.